package com.sky.mapper;

import com.github.pagehelper.Page;
import com.sky.annotation.AutoFill;
import com.sky.dto.DishDTO;
import com.sky.dto.DishPageQueryDTO;
import com.sky.entity.Dish;
import com.sky.enumeration.OperationType;
import org.apache.ibatis.annotations.*;

import java.util.LinkedList;
import java.util.List;
import java.util.Map;

@Mapper
public interface DishMapper {

    /**
     * 根据分类id查询菜品数量
     * @param categoryId
     * @return
     */
    @Select("select count(id) from dish where category_id = #{categoryId}")
    Integer countByCategoryId(Long categoryId);

    /**
     * 新增菜品
     * @param
     * @return
     */
    @AutoFill(value = OperationType.INSERT)
    void sava(Dish dish);

    /**
     * 菜品分页查询
     */
    Page<Dish> dishPage(DishPageQueryDTO dto);

    /**
     * 菜品删除
     */
    @Delete("delete from dish where id = #{id}")
    void dishDelete(Long id);

    /**
     * 根据ID查询菜品
     */
    @Select("select * from dish where id = #{id}")
    Dish getById(Long id);

    /**
     * 菜品起售或停止
     */
    @Update("update dish set status = #{status} where id = #{id}")
    void startOrStop(String status, String id);

    //根据ID回显数据
    @Select("select * from dish where id = #{id}")
    DishDTO getById1(String id);
    @AutoFill(value = OperationType.UPDATE)
    void dishUpdate(Dish dish);



    /**
     * 动态条件查询菜品
     * @param dish
     * @return
     */
    List<Dish> list(Dish dish);



    /**
     * 根据套餐id查询菜品
     * @param setmealId
     * @return
     */
    @Select("select a.* from dish a left join setmeal_dish b on a.id = b.dish_id where b.setmeal_id = #{setmealId}")
    List<Dish> getBySetmealId(Long setmealId);



    /**
     * 根据条件统计菜品数量
     * @param map
     * @return
     */
    Integer countByMap(Map map);

}
